package co.fitstart.entity.market.template;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Where;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
 * 每天课件
 * 
 * @author dan
 *
 */
@Entity
@Table(name = "market_daily_courseware_template")
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class MarketDailyCoursewareTemplate {
    
    @Id
    @GeneratedValue
    private Long id;
    
    /** 名称 */
    private String name;
    
    /** 第几天 */
    private int sorting;
    
    /** 描述 */
    private String description;
    
    /** 动作数 */
    private int actionAmount;
    
    /** 预计分钟数 */
    private int minutes;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private MarketBatchCoursewareTemplate batch;
    
    @OneToMany(mappedBy = "daily", fetch = FetchType.LAZY)
    @Where(clause = "is_disabled = 0")
    @JSONField(serialize = false)
    private List<MarketCoursewareTemplate> coursewares;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * The default constructor
     */
    public MarketDailyCoursewareTemplate() {
        
    }
    
    /**
     * 
     * @param name
     * @param sorting
     * @param description
     * @param batch
     */
    public MarketDailyCoursewareTemplate(String name, int sorting, String description, MarketBatchCoursewareTemplate batch) {
        this.name = name;
        this.sorting = sorting;
        this.description = description;
        this.actionAmount = 0;
        this.minutes = 0;
        this.batch = batch;
        this.disabled = false;
    }
    
    /**
     * 
     * @return
     */
    public MarketDailyCoursewareTemplate disable() {
        this.disabled = true;
        return this;
    }
    
    /**
     * 
     * @return
     */
    public MarketDailyCoursewareTemplate editActionAmount(int actionAmount) {
        this.actionAmount = this.actionAmount + actionAmount;
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the sorting
     */
    public int getSorting() {
        return sorting;
    }

    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @return the actionAmount
     */
    public int getActionAmount() {
        return actionAmount;
    }

    /**
     * @return the minutes
     */
    public int getMinutes() {
        return minutes;
    }

    /**
     * @return the batch
     */
    public MarketBatchCoursewareTemplate getBatch() {
        return batch;
    }

    /**
     * @return the coursewares
     */
    public List<MarketCoursewareTemplate> getCoursewares() {
        return coursewares;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param sorting the sorting to set
     */
    public void setSorting(int sorting) {
        this.sorting = sorting;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * @param actionAmount the actionAmount to set
     */
    public void setActionAmount(int actionAmount) {
        this.actionAmount = actionAmount;
    }

    /**
     * @param minutes the minutes to set
     */
    public void setMinutes(int minutes) {
        this.minutes = minutes;
    }

    /**
     * @param batch the batch to set
     */
    public void setBatch(MarketBatchCoursewareTemplate batch) {
        this.batch = batch;
    }

    /**
     * @param coursewares the coursewares to set
     */
    public void setCoursewares(List<MarketCoursewareTemplate> coursewares) {
        this.coursewares = coursewares;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }

}
